<template>
	<div id="app">
		<router-view />
	</div>
</template>
<script>
	//有没有登录
	//登录：进到首页
	//未登录：进到登录页；

	export default {
		data() {
			return {
				t1: 0,
				baseUrl: require("./assets/baseUrl").baseUrl,
				adminId: 0
			}

		},
		methods: {
			async loginout() {
				//localStorage.setItem("loginout", sessionStorage.getItem("adminId"))
				await this.$http.post(this.baseUrl + "admin/changeLog", {
				 	adminId: sessionStorage.getItem("adminId"),
					logStatus: 0
				}).then(res => {})
			},
			beforeunloadFn() {
				var d = new Date()
				this.t1 = d.getTime();
				//localStorage.setItem("time", this.t1);
			},
			unloadFn() {
				var d = new Date()
				var t2 = d.getTime();
				//localStorage.setItem("unloadFn", t2);
				if (t2 - this.t1 < 5) {
					this.loginout();
				}

			},
		},
		mounted() {
			// this.adminId=sessionStorage.getItem("adminId") 
		
			if(window.addEventListener){
				window.addEventListener("beforeunload", this.beforeunloadFn)
				window.addEventListener("unload", this.unloadFn)
			}else{
				window.attachEvent("onbeforeunload", this.beforeunloadFn)
				window.attachEvent("onunload", this.unloadFn)
			}
			
			if (sessionStorage.getItem("username")) { //登录过
				//
				this.$router.push("/homepage")
			} else {
				this.$router.push("/login")
			}
		}
	}
</script>

<style lang="less">
	#app {
		font-family: Avenir, Helvetica, Arial, sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;

		color: #2c3e50;
		min-height:800px;
	}

	.home {
		width: 100%;
		min-height: 800px;
		background: #fcfcfc;
	}

	.home .navs {
		a {
			font-weight: bold;
			color: #7E7E7E;
			display: block;
			text-decoration: none;
			line-height: 30px;

			&.link-active {
				color: #333;
				background-color: rgba(211, 211, 211, 0.5);
			}
		}
	}
</style>